include:
  - pkg.pkg-init
  - pcre.install
  - zlib.install
  - user.web
/var/cache/nginx:
  file.directory:
    - user: web
    - group: web
    - mode: 755
    - makedirs: True
nginx_dependence:
  pkg.installed:
    - names:
      - gd
      - gd-devel
nginx-source-install:
  file.managed:
    - name: /usr/local/src/nginx-1.12.2.tar.gz
    - source: salt://nginx/files/nginx-1.12.2.tar.gz
    - user: root
    - group: root
    - mode: 755
  cmd.run:
    - name: cd /usr/local/src && sudo tar xf nginx-1.12.2.tar.gz && cd nginx-1.12.2 && sudo ./configure --prefix=/usr/local/nginx --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp  --user=web --group=web --with-file-aio --with-threads  --with-http_addition_module --with-http_auth_request_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_realip_module --with-http_secure_link_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module  --with-stream --with-stream_ssl_module  --with-http_image_filter_module --with-pcre=/usr/local/src/pcre-8.41 --with-zlib=/usr/local/src/zlib-1.2.11 && sudo make && sudo make install
    - unless: test -d /usr/local/nginx
    - require:
      - file: nginx-source-install
      - pkg: pkg-init
      - cmd: pcre-source-install
      - cmd: zlib-source-install
      - user: web-user-group 
